
package io.goeasy.springbootdemo;

import java.util.Map;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@SpringBootApplication
@RestController
public class SpringbootDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootDemoApplication.class, args);
    }

    @RequestMapping("/hello")
    @ResponseBody
    public ResponseEntity hello(@RequestHeader Map<String, String> headers,
                        @RequestParam(required = false) Map<String, String> params, @RequestBody(required = false) String body) {
        String requestId = headers.get("x-fc-request-id");
        System.out.printf("FC Invoke Start RequestId: %s%n", requestId);
        System.out.println(headers.toString());
        System.out.println(params.toString());
        System.out.println(body);
        System.out.printf("FC Invoke End RequestId: %s%n", requestId);
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.TEXT_PLAIN);
        return new ResponseEntity<>("Hello World", responseHeaders, HttpStatus.OK);
    }

    @RequestMapping("/haiyang")
    @ResponseBody
    public ResponseEntity age(@RequestHeader Map<String, String> headers,
                      @RequestParam(required = false) Map<String, String> params, @RequestBody(required = false) String body) {
        String age = params.get("age");
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.TEXT_PLAIN);
        return new ResponseEntity<>("haiyang age: "+ age, responseHeaders, HttpStatus.OK);
    }

    @RequestMapping("/chuanbao")
    @ResponseBody
    public ResponseEntity chuanbao(@RequestHeader Map<String, String> headers,
                      @RequestParam(required = false) Map<String, String> params, @RequestBody(required = false) String body) {
        String chuanbao = params.get("chuanbao");
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.TEXT_PLAIN);
        return new ResponseEntity<>("chuanbao : "+ chuanbao, responseHeaders, HttpStatus.OK);
    }
}